//手机号码的校验
const checkPhone = (val: string): boolean => {
    return /^[1][3,4,5,6,7,8,9][0-9]{9}$/.test(val)
}

//邮箱
const checkEmail = (val: string): boolean => {
    return /^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(val)
}

//身份证的校验
const checkCardId = (val: string): boolean => {
    return /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/.test(val)
}

//URL的校验
const checkUrl = (val: string): boolean => {
    return /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/.test(val)
}

//IPv4的校验
const checkIpv4 = (val: string): boolean => {
    return /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(val)
}

//16进制颜色的校验
const checkColor = (val: string): boolean => {
    return /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/.test(val)
}

//日期 YYYY-MM-DD
const checkDate = (val: string): boolean => {
    return /^\d{4}(\-)\d{1,2}\1\d{1,2}$/.test(val)
}

//日期时间 YYYY-MM-DD hh:mm:ss
const checkDateTime = (val: string): boolean => {
    return /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/.test(val)
}

//整数的校验
const checkInt = (val: string): boolean => {
    return /^[-+]?\d*$/.test(val)
}

//正整数
const checkInteger = (val: string): boolean => {
    return /(^[0-9]\d*$)/.test(val)
}

//小数的校验
const checkFloat = (val: string): boolean => {
    return /^[-\+]?\d+(\.\d+)?$/.test(val)
}

//邮政编号的校验
const checkPostalNo = (val: string): boolean => {
    return /^\d{6}$/.test(val)
}

//QQ号的校验 {5-11位数字}
const checkQQ = (val: string): boolean => {
    return /^[1-9][0-9]{4,10}$/.test(val)
}

//微信号的校验 (6至20位，以字母开头，字母，数字，减号，下划线)
const checkWechartId = (val: string): boolean => {
    return /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/.test(val)
}

//车牌号的校验
const checkCardNo = (val: string): boolean => {
    return /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/.test(val)
}

//只含字母的字符串
const checkLetter = (val: string): boolean => {
    return /^[a-zA-Z]+$/.test(val)
}

//包含中文的字符串
const checkCN = (val: string): boolean => {
    return /[\u4E00-\u9FA5]/.test(val)
}

//密码强度的校验 {密码中必须包含字母、数字、特称字符，至少8个字符，最多30个字符}
const checkUserName = (val: string): boolean => {
    return /(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}/.test(val)
}

//长度8~16位: 须包含数字，小写字母，大写字母，特殊字符(!@#$_.)四种类型， 不允许有连续三位重复!
const checkPassword = (val: string): boolean => {
    return /^(?=.*[0-16])(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$,\.])[0-9a-zA-Z!@#$,\.]{8,16}$/.test(val)
}

//html标记
const checkHTMLtag = (val: string): boolean => {
    return /<("[^"]*"|'[^']*'|[^'">])*>/g.test(val)
}

//匹配http | https的字符串
const checkHTTP = (val: string, str: string): boolean => {
    if (!str || str === "http") return /http.*?(?:\")/gi.test(val)
    if (str === "https") return /https.*?(?:\")/gi.test(val)
    return false
}

//判断字符串是否包含空格
const isIncludeSpaceMiddle = function (val: string): boolean {
    return new RegExp(/\s+/g).test(val)
}

export {
    checkPhone,
    checkEmail,
    checkCardId,
    checkUrl,
    checkIpv4,
    checkColor,
    checkDate,
    checkDateTime,
    checkInt,
    checkInteger,
    checkFloat,
    checkPostalNo,
    checkQQ,
    checkWechartId,
    checkCardNo,
    checkLetter,
    checkCN,
    checkUserName,
    checkPassword,
    checkHTMLtag,
    checkHTTP,
    isIncludeSpaceMiddle,
}
